new Vue({
    el:'#main',
    data:()=>({
        data:[],
        cond:{
            all:true,
            play:false,
            sign:false,
            receipt:false,
            del:false,
            searchText:''
        },
        
        is_content:true,
        is_zwxd:true,
        cheval:[],
        allche:false,
        store:[false,false,false,false],
        order:false,//升序或降序
        sortname:''
    }),
    methods:{
        getdata(){
            $.ajax({
                url:'/admin/Buypo/list',
                type:'post',
                data:this.cond,
                success:(data)=>{
                    data = JSON.parse(data)
                    this.data = data;
                    this.cheval=[]
                    this.data.forEach(element => {
                        this.cheval.push({
                            val:false,
                            id:element.id
                        })
                    });
                    console.log(this.data)
                }
            })
        },
        printf(){//打印
            $('a').hide()
            $('.btn-group').hide()
            $("#printArea").jqprint();
            $('a').show()
            $('.btn-group') .show()
        },
        batch(urlstr){
            var data={buy_po_ids:[]}
            this.cheval.forEach(element => {
                if(element.val)
                data.buy_po_ids.push(element.id)
            });
             $.ajax({
                url:'/admin/buypo/'+urlstr,
                type:'post',
                data,
                success:data=>{
                    data = JSON.parse(data)
                    change_mes_type('.modal-body .alert',data.status)
                    $('.column .alert').show()
                    $('.column .alert p').html(data.msg)
                    if(data.status==1){
                        this.getdata()
                    }
                }
            }) 
        },
        changeall(){
            this.cheval.forEach(element=>{
                element.val= this.allche
            })
        },
        oneaction(urlstr,id){
            $.ajax({
                url:'/admin/buypo/'+urlstr,
                type:'post',
                data:{
                    buy_po_ids:[id]
                },
                success:data=>{
                    data = JSON.parse(data)
                    change_mes_type('.alert',data.status)
                    $('.column .alert').show()
                    $('.column .alert p').html(data.msg)
                    if(data.status==1){
                        this.getdata()
                    }
                }
            })  
        },
        storing(i_order,keyname){
            this.order=this.store[i_order]
            this.store[i_order]=!this.store[i_order]
            this.sortname=keyname
            this.data.sort(this.sortoneData)
        },
        sortoneData(a, b) { 
            if (this.order == 1) {
                return b[this.sortname] - a[this.sortname]
            } else {
                return a[this.sortname] - b[this.sortname]
            }
        }
    },
    mounted(){
        this.getdata()
    },
    watch:{
        cheval:{
            handler(){
                if(this.cheval.every(element=>element.val) && this.cheval.length){
                    this.allche=true
                }else{
                    this.allche=false
                }
            },
            immediate:false,
            deep:true
        }
    }
})